/*    */ package com.zimbra.cs.service.admin;
/*    */ 
/*    */ import com.zimbra.common.account.Key.ServerBy;
/*    */ import com.zimbra.common.localconfig.KnownKey;
/*    */ import com.zimbra.common.localconfig.LC;
/*    */ import com.zimbra.common.mime.ContentDisposition;
/*    */ import com.zimbra.common.service.ServiceException;
/*    */ import com.zimbra.common.util.ByteUtil;
/*    */ import com.zimbra.cs.account.AuthToken;
/*    */ import com.zimbra.cs.account.Provisioning;
/*    */ import com.zimbra.cs.account.Server;
/*    */ import com.zimbra.cs.rmgmt.RemoteManager;
/*    */ import com.zimbra.cs.rmgmt.RemoteResult;
/*    */ import com.zimbra.cs.servlet.ZimbraServlet;
/*    */ import java.io.ByteArrayInputStream;
/*    */ import java.io.IOException;
/*    */ import javax.servlet.ServletException;
/*    */ import javax.servlet.http.HttpServletRequest;
/*    */ import javax.servlet.http.HttpServletResponse;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class CollectLDAPConfigZimbra
/*    */   extends ZimbraServlet
/*    */ {
/*    */   private static final String DOWNLOAD_CONTENT_TYPE = "application/x-compressed";
/*    */   
/*    */   protected void doGet(HttpServletRequest req, HttpServletResponse resp)
/*    */     throws ServletException, IOException
/*    */   {
/*    */     try
/*    */     {
/* 48 */       AuthToken authToken = getAdminAuthTokenFromCookie(req, resp);
/* 49 */       if (authToken == null) {
/* 50 */         resp.sendError(401);
/*    */       }
/*    */       
/* 53 */       if (!authToken.isAdmin()) {
/* 54 */         resp.sendError(401);
/*    */       }
/*    */       
/* 57 */       Provisioning prov = Provisioning.getInstance();
/* 58 */       String ldapHost = LC.ldap_host.value();
/* 59 */       if (ldapHost == null) {
/* 60 */         throw ServiceException.INVALID_REQUEST("Cannot find value for ldap_host in local config", null);
/*    */       }
/* 62 */       Server server = prov.get(Key.ServerBy.name, ldapHost);
/* 63 */       if (server == null) {
/* 64 */         throw ServiceException.INVALID_REQUEST("Cannot find server record for LDAP master host: " + ldapHost, null);
/*    */       }
/*    */       
/* 67 */       RemoteManager rmgr = RemoteManager.getRemoteManager(server);
/* 68 */       RemoteResult rr = rmgr.execute("zmcollectldapzimbra");
/*    */       
/* 70 */       resp.setContentType("application/x-compressed");
/* 71 */       ContentDisposition cd = new ContentDisposition("inline").setParameter("filename", ldapHost + ".ldif.gz");
/* 72 */       resp.addHeader("Content-Disposition", cd.toString());
/* 73 */       ByteUtil.copy(new ByteArrayInputStream(rr.getMStdout()), true, resp.getOutputStream(), false);
/*    */     } catch (ServiceException e) {
/* 75 */       returnError(resp, e);
/* 76 */       return;
/*    */     }
/*    */   }
/*    */   
/*    */ 
/*    */   protected void doPost(HttpServletRequest req, HttpServletResponse resp)
/*    */     throws ServletException, IOException
/*    */   {
/* 84 */     doGet(req, resp);
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/admin/CollectLDAPConfigZimbra.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */